<?php
class Helper_dboutput
{
	private $_data ;
	private $_split;
	/**
	 * 
	 * Enter description here ...
	 * @param 数组 $data
	 */
	function __construct($data,$split = ',')
	{
		$this->_data = $data;
		$this->_split = $split;
	}
	
	function output_txt()
	{
		$savePath = $dir = realpath(Q::ini('log_writer_dir'));
		$tmpFilename = date('Y-m-d',time()).time().'.txt';
		$filepath = $savePath.'/'.$tmpFilename;
		$handle = fopen($filepath, 'w');
		if ($handle)
		{
			foreach ($this->_data as $v)
			{
				$lineString = implode($this->_split, $v);
				$lineString = $lineString . "\r\n";
				fwrite($handle, $lineString);
			}
			fclose($handle);
			$file = fopen($filepath,"r");
			Header("Content-type: application/octet-stream"); 
			Header("Accept-Ranges: bytes");
			Header("Accept-Length: ".filesize($filepath));
			Header("Content-Disposition: attachment; filename=" . $tmpFilename);
			echo fread($file,filesize($filepath)); 
			fclose($file);
			@unlink($filepath);
			exit;
		}
	}
}
?>